<?php
/**
 * Copyright (c) 2014-2018, www.kuacg.com
 * All right reserved.
 *
 * @since LTS-181021
 * @package Cute
 * @author 酷ACG资源网
 * @date 2018/10/21 10:00
 * @link https://www.kuacg.com/23856.html
 */
?>
<?php

/**
 * Class StatisticWidget
 */
class StatisticWidget extends WP_Widget {
    function __construct() {
        parent::__construct(false, __('TT-站点统计小工具', 'tt'), array( 'description' => __('TT-显示站点统计信息，如文章总数，用户总数等', 'tt') ,'classname' => 'widget_Statistic wow bounceInRight'));
    }

    function widget($args, $instance) {
        // parent::widget($args, $instance); // TODO: Change the autogenerated stub
        // extract($args);
        wp_reset_postdata();
        $vm = MgStatusVM::getInstance();
        if($vm->isCache && $vm->cacheTime) {
            echo '<!-- Statistic widget cached ' . $vm->cacheTime . ' -->';
        }
        $info = $vm->modelData;
        ?>
        <?php echo $args['before_widget']; ?>
        <?php if($instance['title']) { echo $args['before_title'] . $instance['title'] . $args['after_title']; } ?>
        <div class="widget-content">
        <div class="dashed">
        <span class="info-posts">文章总数：<?php echo $info->post_count; ?>篇</span>
        <span class="info-comments">评论总数：<?php echo $info->comment_count; ?>条</span>
        </div>
        <div class="dashed">
        <span class="info-tags">标签总数：<?php echo $info->tag_count; ?>个</span>
        <span class="info-categorys">分类总数：<?php echo $info->category_count; ?>个</span>
        </div>
        <div class="dashed">
        <span class="info-users">用户总数：<?php echo $info->user_count; ?>位</span>
        <span class="info-products">商品总数：<?php echo $info->product_count; ?>个</span>
        </div>
        <div class="dashed">
        <span class="info-last-time">最后更新：<?php echo $info->last_modified; ?></span>
        <span class="info-links">友情链接：<?php echo $info->links_count; ?>个</span>
        </div>
        <div class="dashed">
        <span class="info-site-time">建站日期：<?php echo $info->site_open_date; ?></span>
        <span class="info-site-days">运行时间：<?php echo $info->site_open_days; ?>天</span>
        </div>
        </div>
        <?php echo $args['after_widget']; ?>
        <?php
    }

    function update($new_instance, $old_instance) {
        return $new_instance;
    }

    function form($instance) { 
        $title = esc_attr(isset($instance['title']) ? $instance['title'] : __('站点统计', 'tt'));
        ?>
        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title：','tt'); ?><input class="input-lg" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
        <?php
    }
}

/* 注册小工具 */
if ( ! function_exists( 'tt_register_widget_Statistic' ) ) {
    function tt_register_widget_Statistic() {
        register_widget( 'StatisticWidget' );
    }
}
add_action( 'widgets_init', 'tt_register_widget_Statistic' );